(function(win, doc, objName) {
  // 定义全局对象
  function Obj() {};
  Obj.prototype = {
    /**
     * 简单cookie获取与设置
     * @param  {string} name  cookie设置或获取
     * @param  {string} value 设置cookie的值
     * @param  {string} op 设置cookie的参数
     */
    cookie: function(name, value, op) {
      // 变量获取
      var op = op || {},
        expires = '',
        d = new Date();
      if (typeof value != 'undefined') {
        if (value === null) {
          op.expires = -1
        }; //删除
        if (op.expires && (typeof op.expires == "number" || op.expires.toUTCString)) {
          if (typeof op.expires == "number") {
            d.setTime(d.getTime() + (op.expires * 36e5))
          } // 以小时为单位
          else {
            d = op.expires
          }
          expires = "; expires=" + d.toUTCString();
        }
        doc.cookie = [name, "=", encodeURIComponent(value), expires, op.path ? ("; path=" + op.path) : "", op.domain ? ("; domain=" + op.domain) : "", op.secure ? "; secure" : ""].join('');
      } else {
        return decodeURIComponent(doc.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + name + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null
      }
    },
    topBannerStyle: function(height) {
      height = height || 100;
      $('head').append('<style>.topBannerBox{width:100%;z-index:9999;background:#292929;height:' + height / 2 + 'px;}.topBannerBox .topBannerBD{position:fixed;top:0;width:100%;height:' + height / 2 + 'px;background:rgba(0,0,0,.75);}.topBannerBox .topBannerAnim{-webkit-transform:translateY(0);transform:translateY(0);-webkit-transition:all .5s cubic-bezier(.19,1,.22,1);transition:all .5s cubic-bezier(.19,1,.22,1);z-index:9999;}.topBannerBox .topBannerAnimHidden{-webkit-transform:translateY(-101%);transform:translateY(-101%);-webkit-transition:all .3s cubic-bezier(.55,.055,.675,.19);transition:all .3s cubic-bezier(.55,.055,.675,.19);z-index:9999;}.topBannerBox .close{position:absolute;top:0;right:0;width:24px;height:' + height / 2 + 'px;line-height:' + height / 2 + 'px;color:#999;padding:0;background:none;font-size:24px;font-family:SimSun,Tahoma,arial,SimHei,sans-serif;text-align:center;text-decoration:none;z-index:9999;}[data-dpr="2"] .topBannerBox,[data-dpr="2"] .topBannerBox. topBannerBD{height:' + height + 'px}[data-dpr="3"] .topBannerBox,[data-dpr="3"] .topBannerBox. topBannerBD{height:' + height * 1.5 + 'px}[data-dpr="2"] .topBannerBox .close{width:48px;height:' + height + 'px;line-height:' + height + 'px;}[data-dpr="3"] .topBannerBox .close{width:72px;height:' + height * 1.5 + 'px;;line-height:' + height * 1.5 + 'px;}.topBannerBox,.topBannerBox *,.topBannerBox:after,.topBannerBox:after,.topBannerBox:before,.topBannerBox:before{box-sizing:border-box}.topBannerBox .txtBox,.topBannerBox .open{position:absolute;top:50%;-webkit-transform:translateY(-50%);transform:translateY(-50%)}.topBannerBox .open{right:32px;display:inline-block;width:88px;line-height:30px;border-radius:3px;font-size:12px;text-decoration:none;color:#fff;text-align:center;white-space:nowrap;background:#ff424b}.topBannerBox .txtBox{left:5px}.topBannerBox .txtBoxTxt{color:#fff;font-size:12px; margin:0 0 0 8px;}.topBannerBox .logoTxt{margin:0 0 2px 0;color:#f9f978;font-size:20px;line-height:1;font-weight:400}.topBannerBox .jisu{color:#a7f96f}.topBannerBox .noad{color:#ffcec5}.topBannerBox .cache{color:#9af5bf}@media screen and (max-width:320px){.topBannerBox .logoTxt{font-size:16px}}@media screen and (max-width:375px){.topBannerBox .logoTxt{font-size:16px}}</style>')
    },
    addBanner: function(content, opt) {
      opt = $.extend({
        height: 100,
        defaltEvent: true
      }, opt);
        this.topBannerStyle(opt.height); //设置样式
      $('body').prepend('<div class="topBannerBox"><div class="topBannerBD topBannerAnim" style="display: block !important;"><a href="javascript:void(0)" class="close">&times;</a>' + content + '</div></div>');

      // 添加事件操作
      this.hiddenBanner(opt.expires); //默认设置关闭后失效时间为关闭阅览器
      if (opt.defaltEvent) {
        this.topBannerAnim(opt.scrollHeight ? opt.scrollHeight : opt.height); //默认执行
      }
    },
    hiddenBanner: function(expires) {
      var that = this;
      $('body').on('click', '.topBannerBox .close', function(event) {
        event.stopPropagation();
        event.preventDefault();
        that.cookie('topBanner2', true, expires ? {
          expires: expires
        } : {
          expires: 0.1
        }); // 默认过期时间为1小时
        $('.topBannerBox').remove();
      })
    },
    topBannerAnim: function(dis) {
      $(win).scroll(function() {
        var obj = $('.topBannerBox .topBannerBD');
        if ($(win).scrollTop() > dis) {
          obj.attr('class', 'topBannerBD topBannerAnimHidden')
        } else {
          obj.attr('class', 'topBannerBD topBannerAnim')
        }
      })
    },
    init: function(data) {
      var _this = this;
      if (_this.cookie('topBanner2')) return;
      var str = '<span class="jisu">极速</span> <span class="noad">无广告</span> <span class="cache">离线缓存</span>';
      _this.addBanner('<div class="txtBox"><h2 class="logoTxt">《知音漫客》APP</h2><p class="txtBoxTxt">'+ str +'</p></div><a href="'+ data.url +'" class="open">打开APP阅读</a>', {scrollHeight: 300, host: data.host});
    }
  };
  win[objName] = new Obj(); // 暴露的全局对象名称
})(window, document, 'topBanner');
topBanner.init({url:'http://a.app.qq.com/o/simple.jsp?pkgname=cn.zymk.comic&ckey=CK1368539785661'})



